package com.blue.prepose.service;

import com.blue.gateway.api.PaymentClient;
import com.blue.gateway.common.request.PayNotifyRequest;
import com.blue.gateway.common.request.PayRequest;
import com.blue.gateway.common.response.PayResponse;
import com.blue.gateway.common.request.RefundRequest;
import com.blue.gateway.common.response.RefundResponse;
import com.blue.gateway.dto.Result;
import com.blue.gateway.enums.PayChannelEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author xiaoyiming
 * @date 2020/5/3 22:42
 * @depiction
 */
@Service
public class PayService {

    @Autowired
    private PaymentClient paymentClient;

    public Result<PayResponse> pay(PayRequest payRequest) {

        Result<PayResponse> result = paymentClient.pay(payRequest);

        return result;
    }

    public Result asyncNotifyAli(String notifyData){
        PayNotifyRequest payNotifyRequest = new PayNotifyRequest();
        payNotifyRequest.setNotifyData(notifyData);
        payNotifyRequest.setPayChannelEnum(PayChannelEnum.ALIPAY);

        return paymentClient.notify(payNotifyRequest);
    }
    public Result asyncNotifyWx(String notifyData){
        PayNotifyRequest payNotifyRequest = new PayNotifyRequest();
        payNotifyRequest.setNotifyData(notifyData);
        payNotifyRequest.setPayChannelEnum(PayChannelEnum.WX);

        return paymentClient.notify(payNotifyRequest);
    }
    public Result<RefundResponse> refund(RefundRequest refundRequest) {
        return paymentClient.refund(refundRequest);
    }
}
